﻿def open_function(dialog,projectID)
#UI.messagebox(projectID)
   #以下编写将相应的skp文件下载到本地，并在su里打开的方法
   require 'open-uri'
     require 'tempfile'
     puts "-----------------------------------------------------"
   begin
     data = open("http://dev.solarpv.top/api/client/project/download?projectId=#{projectID}", 'User-Agent' => 'ruby'){|f|f.read}
     file = Tempfile.new (["Project"+"#{projectID}"+"-", '.skp'])
     file.binmode
     file << data
     file.flush
     file.close
     #puts file.path
     result = Sketchup.open_file("#{file.path}")
     #UI.messagebox("stats:200  message: 项目已经打开")#测试字符串
      dialog.execute_script("openFileStats(200,'下载成功')")
      rescue
      puts "download error"
     # UI.messagebox("stats:300  message: 下载失败")#测试字符串
       dialog.execute_script("openFileStats(300,'下载失败')")
       end

end